package dictionary;

import java.util.HashMap;
import java.util.Iterator;

public class DicDaoMap implements DicDao {
    private HashMap<String,MyDic> map=new HashMap<String,MyDic>();
    @Override
    public void save(MyDic myDic) {
        String key=myDic.getEnglish();
        map.put(key,myDic);
    }

    @Override
    public MyDic query(String name) {
        if (map.containsKey(name)){
            return map.get(name);
        }
       return null;
    }

    @Override
    public void queryall() {
        System.out.println("词典中的所有内容：");
        //遍历集合
        Iterator iterator=map.keySet().iterator();
        while (iterator.hasNext()){
            String key=(String) iterator.next();
            MyDic value=map.get(key);
            System.out.println(value);
        }

    }

    @Override
    public void delect(String name) {
        if (map.containsKey(name)){
            map.remove(name);
            System.out.println("该单词已删除");
        }else {
            System.out.println("该单词不存在");
        }

    }
}
